package com.lyz.dataStructure.JianZhiOffer.array;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 17:38
 * @Description:
 **/

import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/6/30 17:38
 *@Description:
 **/
/*
题目描述
{6, -3, -2, 7, -15, 1, 2, 2}，连续子数组的最大和为 8（从第 0 个开始，到第 3 个为止）。
求连续字数组的最大和。
 */

public class Test27 {
    public static int FindGreatestSumOfSubArray(int[] array) {
        if(array.length==0||array==null){
            return -1;
        }
        int maxSum = Integer.MIN_VALUE;
        int sum = 0;
        for(int val : array){
            if(sum<=0){
                sum =val;
            }else{
                sum =sum +val;
            }
            maxSum = Math.max(maxSum,sum);
        }
        return maxSum;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String s = sc.nextLine();
            String[] st = s.split(",");
            int[] array = new int[st.length];
            for(int i =0;i<array.length;i++){
                array[i] = Integer.parseInt(st[i]);
            }
            System.out.println(FindGreatestSumOfSubArray(array));
        }
    }
}
